﻿using System.Diagnostics.Contracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace YaTools.Yaml.UnitTests
{
    /// <summary>
    ///This is a test class for StringCacheTest and is intended
    ///to contain all StringCacheTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StringCacheTest
    {
        /// <summary>
        ///A test for GetString
        ///</summary>
        [TestMethod()]
        [ContractVerification(false)]
        public void GetStringTest()
        {
            StringCache target = new StringCache();
            char[] buffer = "One two six one two six".ToCharArray();
            string[] values = new string[6];

            for (int start = 0, i = 0; start < buffer.Length; start += 4, i++)
            {
                values[i] = target.GetString(new BufferSegment(buffer, start, 3));
            }

            Assert.AreNotEqual(values[0], values[3]);
            Assert.AreEqual(values[0].ToLower(), values[3]);
            Assert.AreEqual(values[1], values[4]);
            Assert.AreEqual(values[2], values[5]);
            Assert.AreSame(values[1], values[4]);
            Assert.AreSame(values[2], values[5]);
            Assert.AreNotEqual(values[0], values[4]);
            Assert.AreNotEqual(values[3], values[4]);
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test dumper which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #region Additional test attributes

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion
    }
}